package com.mediacloud.app.newsmodule.fragment.ugc.detail


import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.os.Handler
import android.text.SpannableString
import android.text.Spanned
import android.text.TextUtils
import android.text.style.ForegroundColorSpan
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.LinearLayout
import android.widget.SeekBar
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.viewpager.widget.ViewPager
import com.chinamcloud.project.shanshipin.activity.IVideoSizeChange
import com.chinamcloud.project.shanshipin.utils.tiktok.TikTokController
import com.chinamcloud.project.shanshipin.utils.tiktok.TikTokRenderViewFactory
import com.chinamcloud.project.shanshipin.utils.tiktok.TimeProgressListener
import com.chinamcloud.project.shanshipin.utils.tiktok.VerticalViewPager
import com.google.android.graphics.SelectStateDrawable
import com.jaeger.library.StatusBarUtil
import com.lzf.easyfloat.utils.DisplayUtils
import com.mediacloud.app.assembly.util.StringUtils
import com.mediacloud.app.assembly.util.load
import com.mediacloud.app.assembly.util.toast
import com.mediacloud.app.model.CommentDismissEvent
import com.mediacloud.app.model.eventbus.event.LoginEvent
import com.mediacloud.app.model.interfaces.DataInvokeCallBack
import com.mediacloud.app.model.news.ArticleItem
import com.mediacloud.app.model.news.ArticleListData
import com.mediacloud.app.model.news.BaseMessageReciver
import com.mediacloud.app.model.news.CatalogItem
import com.mediacloud.app.model.utils.DefaultBgUtil
import com.mediacloud.app.newsmodule.R
import com.mediacloud.app.newsmodule.activity.HandleDataCollectActivity
import com.mediacloud.app.newsmodule.adaptor.comment.x.XCommentDialogFragment
import com.mediacloud.app.newsmodule.addnewslike.m.AddLikeDataInvoke
import com.mediacloud.app.newsmodule.addnewslike.p.NewsLikePresenter
import com.mediacloud.app.newsmodule.addnewslike.v.ILikesNumUpdate
import com.mediacloud.app.newsmodule.utils.*
import com.mediacloud.app.newsmodule.utils.share.ShareWrap
import com.mediacloud.app.newsmodule.utils.support.SupportKit
import com.mediacloud.app.newsmodule.view.CommentDialog
import com.mediacloud.app.reslib.enums.AppFactoryGlobalConfig
import com.mediacloud.app.reslib.util.DataInvokeUtil
import com.mediacloud.app.user.model.UserInfo
import com.tencent.mm.opensdk.utils.Log
import com.yoake.media.player.utils.cache.PreloadManager
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.activity_liteav_detail.*
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import org.json.JSONObject
import xyz.doikki.videoplayer.player.BaseVideoView
import xyz.doikki.videoplayer.player.VideoView
import xyz.doikki.videoplayer.util.L


@SuppressLint("RestrictedApi")
class LiteAvDetailActivity : HandleDataCollectActivity(), DataInvokeCallBack<ArticleListData>, ILikesNumUpdate, CollectionController.CollectStatusListener {
    companion object {

        @JvmStatic
        fun startActivity(context: Context, mod: LiteAvStartMod,requestCode:Int=-1) {
            val intent = Intent(context, LiteAvDetailActivity::class.java)
            mod.items.forEach {
                it.content = null
                it.customColumns = null
                it.customColumn = null
                it.movie = null
            }
            intent.putExtra("MOD", mod)
            if (context is Activity &&requestCode>0){
                context.startActivityForResult(intent,requestCode)
            }else {
                context.startActivity(intent)
            }
        }
    }

    private val items: MutableList<ArticleItem> = ArrayList()
    private var player: VideoView? = null
    private var mPreloadManager: PreloadManager? = null
    private var mController: TikTokController? = null
    lateinit var adapter: LiteAvDetailAdapter
    lateinit var mod: LiteAvStartMod
    var newsLikePresenter: NewsLikePresenter? = null
    var newsDetailDataInvoker: NewsDetailInvoker? = null
    var dataInvoker: NewsListDataInvoker? = null
    val pageSize = 15
    var haveMore = true
    var pageIndex: Int = -1
    var mPlayPosition: Int = 0
    var catalogId: String? = null
    var limitVideoCount: Int = 0
    protected var collectionController: CollectionController? = null
    private var collectSourceId: String? = null

    //分享相关
    var shareWrap: ShareWrap? = null
    override fun getLayoutResID(): Int {
        return R.layout.activity_liteav_detail
    }

    override fun getFitSystemWindow(): Boolean {
        return false
    }

    private fun initVideoView() {
        if(!EventBus.getDefault().isRegistered(this)){
            EventBus.getDefault().register(this)
        }
        player = VideoView(this)
        player?.setLooping(true)
        player?.setRenderViewFactory(TikTokRenderViewFactory.create(object : IVideoSizeChange {
            override fun onVideoSize(videoWidth: Int, videoHeight: Int) {
                //这样做是防汁闪屏的问题，取到了视频大小在设置宽高
                player?.layoutParams?.let {
                    it as FrameLayout.LayoutParams
                    it.height = FrameLayout.LayoutParams.WRAP_CONTENT
                    it.width = FrameLayout.LayoutParams.MATCH_PARENT
                    it.gravity = Gravity.CENTER_VERTICAL
                    player?.layoutParams = it
                }
                if (videoWidth > videoHeight) {
                    toggleButton.visibility = View.VISIBLE
                } else {
                    toggleButton.visibility = View.GONE
                }
            }
        }))

        mController = TikTokController(this)
        mController?.timeProgressListener = object : TimeProgressListener {
            override fun onTimeProgress(duration: Int, position: Int) {
                seekbar?.max = duration
                seekbar?.progress = position

            }
        }
        player?.addOnStateChangeListener(object : BaseVideoView.OnStateChangeListener {
            override fun onPlayStateChanged(playState: Int) {
                Log.e("wywwy", "" + playState)
                if (VideoView.STATE_PLAYING == playState || VideoView.STATE_BUFFERED == playState) {
                    mController?.startProgress()
                } else {
                    mController?.stopProgress()
                }
                when (playState) {
                    VideoView.STATE_IDLE -> {
                        thumb.visibility = View.VISIBLE
                    }
                    VideoView.STATE_PLAYING -> {
                        thumb.visibility = View.GONE
                        iv_isplay.setImageResource(R.drawable.icon_playing)
                        Handler().postDelayed({
                            iv_isplay.setImageResource(0)
                        }, 100)
                    }
                    VideoView.STATE_PAUSED -> {
                        iv_isplay.setImageResource(R.drawable.icon_stop)
                    }
                }
            }

            override fun onPlayerStateChanged(playerState: Int) {
            }
        })
        player?.setVideoController(mController)
    }

    private fun initViewPager() {
        mPreloadManager = PreloadManager.getInstance(this)
        mViewPager.offscreenPageLimit = 4
        intent.getParcelableArrayListExtra<ArticleItem>(Intent.ACTION_ATTACH_DATA)?.let {
            items.clear()
            items.addAll(it)
        }
        if (limitVideoCount != 0) {
            limitVideoCount += items.size
        }
        adapter = LiteAvDetailAdapter(this, items)
        mViewPager.adapter = adapter
        mViewPager.overScrollMode = View.OVER_SCROLL_NEVER
        mViewPager.currentItem = mPlayPosition
        mViewPager.post { startPlay(mPlayPosition) }
        mViewPager.setOnPageChangeListener(object : ViewPager.SimpleOnPageChangeListener() {
            private var mCurItem = 0

            /**
             * VerticalViewPager是否反向滑动
             */
            private var mIsReverseScroll = false

            override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
                super.onPageScrolled(position, positionOffset, positionOffsetPixels)
                if (position == mCurItem) {
                    return
                }
                mIsReverseScroll = position < mCurItem
            }

            override fun onPageSelected(position: Int) {
                super.onPageSelected(position)
                if (position == mPlayPosition) return
                startPlay(position)
                setVideoInfo()
                Log.e("YYYYYY", "onPageSelected")
            }

            override fun onPageScrollStateChanged(state: Int) {
                super.onPageScrollStateChanged(state)
                Log.e("YYYYYY", "onPageScrollStateChanged $state")
                if (state == VerticalViewPager.SCROLL_STATE_DRAGGING) {
                    mCurItem = mViewPager.currentItem
                }
                if (state == VerticalViewPager.SCROLL_STATE_IDLE) {
                    mPreloadManager?.resumePreload(mPlayPosition, mIsReverseScroll)
                } else {
                    mPreloadManager?.pausePreload(mPlayPosition, mIsReverseScroll)
                }
            }
        })
    }

    private fun removeViewFormParent(v: View?) {
        if (v == null) return
        val parent = v.parent
        if (parent is FrameLayout) {
            parent.removeView(v)
        }
    }

    lateinit var thumb: View
    private fun startPlay(position: Int) {
        val count = mViewPager.childCount
        for (i in 0 until count) {
            val viewHolder = mViewPager.getChildAt(i).tag as LiteAvDetailAdapter.ViewHolder
            if (viewHolder.mPosition == position) {
                player?.release()
                removeViewFormParent(player)
                val item: ArticleItem = items[position]
                setVideoView(viewHolder, item.tipVideoAdress, position)
                break
            }
        }
    }

    private fun setVideoView(viewHolder: LiteAvDetailAdapter.ViewHolder, url: String, position: Int) {
        thumb = viewHolder.mThumb
        val playUrl = mPreloadManager?.getPlayUrl(url)
        L.i("startPlay: position: $position  url: $playUrl")
        player?.setUrl(playUrl)
        mController?.addControlComponent(viewHolder.mTikTokView, true)
        //将videoView放在背景跟封面图之间
        viewHolder.mPlayerContainer.addView(player, 1)
        //先将视频控件宽高设为0，等拿到具体宽高之后再设置，否则会闪屏
        player?.layoutParams?.let {
            it as FrameLayout.LayoutParams
            it.height = 0
            it.width = 0
            it.gravity = Gravity.CENTER_VERTICAL
            player?.layoutParams = it
        }
        player?.start()
        mPlayPosition = position
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val uriData = intent.data
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this)
        }
        collectionController = CollectionController(this, CatalogItem(), null, this);
        if (uriData != null) {
            val articleId = uriData.getQueryParameter("articleid")
            val title = uriData.getQueryParameter("title")
            val cname = uriData.getQueryParameter("cname")
            val tag = uriData.getQueryParameter("tag")
            getDetail("$articleId", true)
        } else {
            var articleId: String? = null
            intent.getStringExtra("article_id")?.let {
                articleId = it
            }
            if (!TextUtils.isEmpty(articleId)) {
                getDetail("$articleId", true)
            } else {
                mod = intent.getParcelableExtra("MOD")!!
                initView()
            }
        }
        val lp = toggleButton.layoutParams as ViewGroup.MarginLayoutParams
        lp.topMargin = DisplayUtils.getScreenWidth(this) / 16 * 11
        toggleButton.layoutParams = lp
        toggleButton.setOnClickListener {
            mController?.toggleFullScreen()
        }

    }

    @Subscribe
    fun loginState(loginEvent: LoginEvent?) {
        if (UserInfo.isLogin(this)) {
            collectionController?.checkCollection()
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this)
        }
        mPreloadManager?.removeAllPreloadTask()
    }

    private fun initView() {
        items.addAll(mod.items)
        pageIndex = mod.pageIndex
        mPlayPosition = mod.position

        limitVideoCount = mod.limitVideoCount
        val likeSelector = SelectStateDrawable(
                ContextCompat.getDrawable(this, R.drawable.douhuier_like_normal)!!,
                ContextCompat.getDrawable(this, R.drawable.douhuier_like_select)!!,
                DefaultBgUtil.getTintColor(this)
        )
        val collectSelector = SelectStateDrawable(
                ContextCompat.getDrawable(this, R.drawable.liteav_start0)!!,
                ContextCompat.getDrawable(this, R.drawable.liteav_start1)!!,
                DefaultBgUtil.getTintColor(this)
        )
        collectImage?.setImageDrawable(collectSelector)
        collectLayout?.setOnClickListener {
            if (UserInfo.isLogin(this)) {
                collectLayout?.isEnabled = false
                collectionController?.collection()
            } else {
                LoginUtils.request_source=LoginUtils.source_collect;
                LoginUtils.invokeLogin(this)
            }
        }
        likeImage?.setImageDrawable(likeSelector)
        newsLikePresenter = NewsLikePresenter(this, this)
        shareWrap = ShareWrap(this, true)
        initVideoView()
        StatusBarUtil.setDarkMode(this)
        initViewPager()
        findViewById<View>(R.id.image_top_back)?.setOnClickListener { finish() }

        if (mod.navigateId?.isEmpty() == true)//直接判断 如果外面不传导航id就为空 不去预加载
        {
            haveMore = false
        }
        commentLayout.setOnClickListener {
            articleItem?.let {
                val fragment = XCommentDialogFragment()
                val bundle = Bundle()
                bundle.putParcelable("data", it)
                bundle.putBoolean("HIDE_COMMENT_ICO", true)
                bundle.putInt("type", 12)
                fragment.arguments = bundle
                fragment.show(supportFragmentManager, "bottom")
                player?.pause()//暂停播放
                fragment.onFragmentCloseCallBack = {
                    player?.resume()
                }
            }
        }
        val letMeSay: LinearLayout = findViewById(R.id.letmesayRootContainer)
        val tvLetMeSay: TextView = findViewById(R.id.letmeSay)
        tvLetMeSay.setTextColor(Color.parseColor("#6F95F7"))
        letMeSay.setOnClickListener {
//            commentDialogFram.articleItem = articleItem
//            commentDialogFram.show(mRootView)
            CommentDialog.startActivity(this@LiteAvDetailActivity,articleItem,false,12)
            player?.pause()
//            commentDialogFram.setOnDismissListener {
//                player?.resume()
//            }
        }
        if (mod.catalog == null) {
            dataInvoker = NewsListDataInvoker(this)
        }

        if (mPlayPosition < 0 || mPlayPosition == items.size) {
            return
        } else {
            setVideoInfo()
        }

        seekbar?.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
            var progress = -1
            override fun onProgressChanged(seekBar: SeekBar?, p: Int, fromUser: Boolean) {
                progress = p
            }

            override fun onStartTrackingTouch(seekBar: SeekBar?) {
                progress = -1
            }

            override fun onStopTrackingTouch(seekBar: SeekBar?) {
                if (progress > 0)
                    player?.seekTo(progress.toLong())
            }
        })


        shareLayout?.setOnClickListener {
            shareWrap?.setShowFunction(false)
            shareWrap?.init(items[mPlayPosition], CatalogItem())
            shareWrap?.show(mRootView);
        }

        topMore?.setOnClickListener {
            shareWrap?.setShowFunction(true)
            shareWrap?.init(items[mPlayPosition], CatalogItem())
            shareWrap?.show(mRootView);
        }

        if (mod.catalog != null && mod.catalog!!.status != "2") {
            shareLayout.visibility = View.GONE
            commentLayout.visibility = View.GONE
            likeLayout.visibility = View.GONE
            userLayout.visibility = View.GONE
            comment_layout.visibility = View.GONE
            topMore.visibility = View.GONE
        }
        onPageStart()
    }
    @Subscribe(threadMode= ThreadMode.MAIN)
    fun onCommentDismiss(event: CommentDismissEvent){
        player?.resume()
    }
    override fun onBackPressed() {
        if (shareWrap!=null&&shareWrap!!.isShowing()) {
            shareWrap?.dismiss();
            return;
        }
        super.onBackPressed()
    }

    private fun getDetail(id: String, init: Boolean = false) {
        DataInvokeUtil.getZiMeiTiApi()
                .getShortVideoDetail(id)
                .subscribeOn(Schedulers.computation())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(object : io.reactivex.Observer<JSONObject> {
                    override fun onSubscribe(d: Disposable) {
                    }

                    override fun onNext(t: JSONObject) {
                        if (t.optBoolean("state")) {
                            t.optJSONObject("data")?.let {

                                if (init) {
                                    val item = ArticleItem.parse(it)

                                    val items: ArrayList<ArticleItem> = ArrayList()
                                    items.add(item)
                                    mod = LiteAvStartMod(items, 0, 0, 0, null, null)
                                    initView()
                                } else {
                                    val id = it.optLong("id")
                                    val size = items.size
                                    for (i in 0 until size) {
                                        val item = items[i]
                                        if (item.id == id) {
                                            item.favorCount_format = it.optString("favorCount_format")
                                            item.commentCount_format = it.optString("commentCount_format")
                                            item.url = it.optString("shareHtml")
                                            item.title = it.optString("title")
                                            item.logo = it.optString("tipImage")
                                            if (id == articleItem.id) {
                                                if (item.favorCount_format.isNullOrEmpty() || item.favorCount_format.equals("0")) {
                                                    likeCount?.text = "赞"
                                                } else {
                                                    likeCount?.text = StringUtils.toTenThousand(item.favorCount_format)
                                                }
                                                commentCount.text = if ("0" == item.commentCount_format) {
                                                    "评论"
                                                } else {
                                                    StringUtils.toTenThousand(item.commentCount_format)
                                                }
                                            }
                                            break
                                        }
                                    }
                                }
                            }
                        }
                    }

                    override fun onError(e: Throwable) {
                    }

                    override fun onComplete() {
                    }
                })
    }

    private fun getListData() {

        DataInvokeUtil.getZiMeiTiApi()
                .getMyVideoList(mod.catalog?.catalog_id, mod.catalog?.user_id, mod.catalog?.status, pageIndex, pageSize)
                .subscribeOn(Schedulers.computation())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(object : io.reactivex.Observer<JSONObject> {
                    override fun onSubscribe(d: Disposable) {
                    }

                    override fun onNext(t: JSONObject) {
                        val data = ArticleListData()
                        data.readFromJson(t);
                        success(data)
                    }

                    override fun onError(e: Throwable) {
                    }

                    override fun onComplete() {
                    }
                })
    }




    private fun preloadNextPageData() {
        if (!haveMore)
            return
        Log.w("XXQA", "预加载下一页数据")
        pageIndex++
        if ((catalogId != null) || (catalogId == null && mod.navigateId == null)) {
            getListData()
        } else {
            dataInvoker?.getContentListWithAd(mod.navigateId, pageIndex, pageSize, null)
        }
    }


    @SuppressLint("SetTextI18n")
    fun setVideoInfo() {
        if (mPlayPosition >= items.size) {
            return
        }


        //切到倒数第二个的时候去预加载下一页的数据
        if (mPlayPosition >= items.size - 2) {
            preloadNextPageData()
        }

        seekbar?.max = 0
        seekbar?.progress = 0
        videoDuration?.text = "00:00/00:00"
        articleItem = items[mPlayPosition]

        collectLayout?.isEnabled = false
        collectSourceId = CollectionController.convertappfacSourceId(articleItem)
        collectionController?.articleItem = articleItem
        collectionController?.checkCollection()
        if (articleItem.location.isNotBlank()) {
            location.visibility = View.VISIBLE
            location.text = articleItem.location
        } else {
            location.visibility = View.GONE
        }
        if (articleItem.catalogName.isNullOrEmpty()) {
            titleText?.visibility = View.GONE
            summary?.text = articleItem.title
        } else {
            titleText?.visibility = View.VISIBLE
            titleText?.text = "@${articleItem.catalogName}"
            val titleStr = articleItem.title.trimEnd()
            val titleAll = "$titleStr #${articleItem.catalogName}"
            val spannableString = SpannableString(titleAll)
            val focusTextColor = ForegroundColorSpan(Color.parseColor("#3368EA"))
            spannableString.setSpan(focusTextColor, titleStr.length, titleAll.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
            summary?.text = spannableString
        }

        readStatusInvoker.readStatistics("${articleItem.id}", 1, 0)
        userIcon.load(articleItem.avatar, ContextCompat.getDrawable(this, R.drawable.new_user_logo_login)!!)
        getDetail("${articleItem.id}")
        NewsLikePresenter.initLikes(newsLikePresenter!!.addLikeDataInvoke, likeImage, likeLayout, likeCount, articleItem, this, 12)
        SupportKit.initSupportViewState(this, SupportKit.getType(articleItem.type), articleItem.getId(), likeImage)
        likeCount.visibility = View.VISIBLE
        if (articleItem.favorCount_format.isNullOrEmpty() || articleItem.favorCount_format.equals("0")) {
            likeCount?.text = "赞"
        } else {
            likeCount?.text = articleItem.favorCount_format
        }
        val catalogItem = CatalogItem()
        catalogItem.catalog_type = AppFactoryGlobalConfig.FeatureModule.BigModule.Lite_Av
        NewsItemClickUtils.addHistory(this, articleItem, catalogItem)
    }

    override fun getStatusBarColor(): Int {
        return Color.TRANSPARENT
    }

    override fun onPause() {
        super.onPause()
        player?.pause()
    }

    override fun onResume() {
        super.onResume()
        player?.resume()
    }

    override fun finish() {
        player?.release()
        dataInvoker?.destory()
        newsDetailDataInvoker?.destory()
//        commentDialogFram?.destory()
        super.finish()
    }


    override fun success(data: ArticleListData?) {
        if (data?.state == false) {
            toast(data.message)
            return
        }
        haveMore = data?.more ?: false
        if (!haveMore) {
            Log.w("XXQA", "没有更多数据了")
        }
        val tempList: MutableList<ArticleItem> = ArrayList()
        data?.articleList?.let {
            tempList.addAll(it)
        }
        tempList.let {
            val iterator = it.iterator()
            while (iterator.hasNext()) {
                val item = iterator.next()
                if (items.contains(item)) {
                    iterator.remove()
                }
            }
            //20200604新加需求，当有浏览视频数量限制时，要去限制加载数量
            if (limitVideoCount == 0) {
                items.addAll(it)
            } else {
                val limit = limitVideoCount - items.size
                //已经最大观看数量
                if (limit <= 0) {
                    return
                }
                //还有limit个可观看的视频
                if (limit <= pageSize) {
                    if (it.size > limit) {
                        items.addAll(it.subList(0, limit))
                    } else {
                        items.addAll(it)
                    }
                } else {
                    items.addAll(it)
                }
            }
//            mVideoList.addAll(it)
            adapter.notifyDataSetChanged()
            Log.w("XXQA", "添加刷新数据")
        }

    }

    override fun fault(data: Any?) {
        pageIndex -= 1
    }

    override fun updateLikesFault(data: Any?) {
        ToastUtil.show(this, "网络异常，请检查网络")
    }

    var readStatusInvoker = ReadStatusInvoker(object : DataInvokeCallBack<BaseMessageReciver?> {
        override fun success(data: BaseMessageReciver?) {
            Log.w(TAG, "readStatusInvoker success")
        }

        override fun fault(data: Any) {
            Log.w(TAG, "readStatusInvoker fault")
        }
    })

    private fun memberAttention() {
        val params: MutableMap<String, String> = HashMap()
        params["attention_uid"] = UserInfo.getUserInfo(this).userid
        params["attentioned_uids"] = ""
        DataInvokeUtil.getZiMeiTiApi()
                .memberAttention(params)
                .subscribeOn(Schedulers.computation())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(object : io.reactivex.Observer<JSONObject> {
                    override fun onSubscribe(d: Disposable) {
                    }

                    override fun onNext(t: JSONObject) {

                    }

                    override fun onError(e: Throwable) {
                    }

                    override fun onComplete() {
                    }
                })
    }

    override fun updateLikesSuccess(data: AddLikeDataInvoke.AddLikeDataReciver?) {
        val item = items[mPlayPosition]
        SupportKit.initSupportViewState(this,SupportKit.TYPE_1,item.id,likeImage)
        try {
            var likes: Long = if (likeCount?.text.toString() == "赞") {
                0
            } else {
                likeCount?.text.toString().toLong()
            }

            if (item.isSupport) {//点赞
                if (data?.state == true) {
                    likes++
                    likeCount?.text = likes.toString()
                } else {
                    updateLikesFault(null)
                    return
                }
            } else {
                //取消点赞s
                if (data?.state == true) {
                    likes--
                    if (likes <= 0) {
                        likeCount?.text = "赞"
                    } else {
                        likeCount?.text = likes.toString()
                    }
                } else {
                    updateLikesFault(null)
                    return
                }
            }
            item.supportCount = likes
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

    override fun updateLikesNum(value: Int) {
        ToastUtil.show(this, "更新数量")
    }


    override fun onCollectionStatus(sourceId: String?, collected: Boolean) {
        if (sourceId == collectSourceId) {
            collectLayout?.isEnabled = true
            collectImage.isSelected = collected
        }
    }

    override fun onCollectionOk(sourceId: String?, collected: Boolean, msg: String?) {
        if (sourceId == collectSourceId) {
            collectLayout?.isEnabled = true
            collectImage.isSelected = collected
        }
    }


    override fun onCollectionErr(msg: String?) {

    }

//    override fun onChanged(status: SpiderStatus) {
//        val item = items[mPlayPosition]
//        item.spider_user.let {
//            if (item.spider_user.userId == status.id) {
//                attention.isSelected = status.status
//            }
//        }
//
//    }


}